package com.erp.itm.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.erp.itm.domain.ProjectLogDO;
import com.erp.itm.service.ProjectLogService;
import com.erp.common.utils.PageUtils;
import com.erp.common.utils.Query;
import com.erp.common.utils.R;

/**
 * 
 * 
 * @author Eric
 * @email shiliang900713@163.com
 * @date 2019-10-08 11:32:59
 */
 
@Controller
@RequestMapping("/itm/projectLog")
public class ProjectLogController {
	@Autowired
	private ProjectLogService projectLogService;
	
	@GetMapping()
	@RequiresPermissions("itm:projectLog:projectLog")
	String ProjectLog(){
	    return "itm/projectLog/projectLog";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("itm:projectLog:projectLog")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ProjectLogDO> projectLogList = projectLogService.list(query);
		int total = projectLogService.count(query);
		PageUtils pageUtils = new PageUtils(projectLogList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("itm:projectLog:add")
	String add(){
	    return "itm/projectLog/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("itm:projectLog:edit")
	String edit(@PathVariable("id") Long id,Model model){
		ProjectLogDO projectLog = projectLogService.get(id);
		model.addAttribute("projectLog", projectLog);
	    return "itm/projectLog/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("itm:projectLog:add")
	public R save( ProjectLogDO projectLog){
		if(projectLogService.save(projectLog)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("itm:projectLog:edit")
	public R update( ProjectLogDO projectLog){
		projectLogService.update(projectLog);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("itm:projectLog:remove")
	public R remove( Long id){
		if(projectLogService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("itm:projectLog:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		projectLogService.batchRemove(ids);
		return R.ok();
	}


	@GetMapping("/listbyitminfo/{id}")
	String listbyitminfo(@PathVariable("id") Long id,Model model){
		model.addAttribute("projectid",id);
		return "itm/projectLog/projectLog";
	}


	@ResponseBody
	@GetMapping("/listbyitm")
	public PageUtils listbyitm(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<ProjectLogDO> projectLogList = projectLogService.list(query);
		int total = projectLogService.count(query);
		PageUtils pageUtils = new PageUtils(projectLogList, total);
		return pageUtils;
	}
}
